<!-- 最近一周人工智能跟踪趋势图 -->
<template>
  <div class="wrap">
    <span class="title">最近一周人工智能跟踪趋势图</span>
  <!-- -->
    <el-col :xs="24" :sm="24" :lg="24">
      <barchart :chartData="list" :height="this.$props.height"/>
    </el-col>
  </div>
</template>

<script>
import { connrequest } from "@/api/firstPage";
import barchart from "./barchart.vue";
import { getNowDay, parseTime } from '@/utils/index.js'

export default {
  props:{
    height:{
      type: String,
      default: '315px'
    }
  },
  components:{barchart},
  data() {
    return {
      list: {xAxis:[],series:[]},
      listTime:[
        {'StartTime':'','EndTime':''},
        {'StartTime':'','EndTime':''},
        {'StartTime':'','EndTime':''},
        {'StartTime':'','EndTime':''},
        {'StartTime':'','EndTime':''},
        {'StartTime':'','EndTime':''},
        {'StartTime':'','EndTime':''}
      ]
	  // barchartData1: {xAxis:[],series:[]},
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getTimeList(i){
      var today = new Date();
      this.listTime[i].StartTime=formatDate(today, 6-i, true)
      this.listTime[i].EndTime=formatDate(today, 6-i, false)
      function formatDate(date, daysToAdd, isStart) {
        var newDate = new Date(date);
        newDate.setDate(date.getDate() - daysToAdd);
        var year = newDate.getFullYear();
        var month = String(newDate.getMonth() + 1).padStart(2, '0');
        var day = String(newDate.getDate()).padStart(2, '0');
        var hours = isStart ? '00' : '23';
        var minutes = isStart ? '00' : '59';
        var seconds = isStart ? '00' : '59';
        return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
      }
    },
    async getData() {
      const endTime = new Date();
      endTime.setHours(23, 59, 59, 999);
      const startTime = new Date();
      startTime.setDate(endTime.getDate() - 7);
      startTime.setHours(0, 0, 0, 0);
      let xAxis = []
      let t1 =[]
      let t2 =[]
      let t3 =[]
      let t4 =[]
      let t5 =[]
      const data = {
        Filter: {
          StartTime: parseTime(startTime),
          EndTime: parseTime(endTime),
          TransDate:'',
          Status:1,
          Account: '',
          SumCount: 10
        }
      }
      const res = await connrequest('GetChatGPTLogSumGroupByNameAndModel', data);
      res.Data = res.Data || []

      res.Data.map( item =>{
        // item.TransTime = parseTime(item.TransTime)
        xAxis.push(item.TransDate)
        // Ids.push(item.ClassID)
        if(item["Gpt 基础"]!== undefined) t1.push(item["Gpt 基础"])
        else t1.push(0)

        if(item["Gpt 高级"] !== undefined) t2.push(item["Gpt 高级"])
        else t2.push(0)

        if(item["豆包"] !== undefined) t3.push(item["豆包"])
        else t3.push(0)

        if(item["本地Deepseek"] !== undefined) t4.push(item["本地Deepseek"])
        else t4.push(0)

        if(item["Deepseek"] !== undefined) t5.push(item["Deepseek"])
        else t5.push(0)
      })
      // this.list = res.Data
      this.list = {xAxis,t1,t2,t3,t4,t5}
      // console.log("list",this.list)
    }
  }
}
</script>

<style lang="scss" scoped>
  .wrap{
    background: #fff;
  }
.night{
  .wrap
  {
    background: #303445;
  }
}
</style>
